// pages/walletRecharge/walletRecharge.js
var app = getApp();
var req = require("../../utils/req.js");
var url = require("../../utils/url.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    money:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  inputPrice:function(e){

    var money;
    if (/^(\d?)+(\.\d{0,2})?$/.test(e.detail.value)) { //正则验证，提现金额小数点后不能大于两位数字
      money = e.detail.value;
    } else {
      money = e.detail.value.substring(0, e.detail.value.length - 1);
    }
    this.setData({
      money: money,
    })
    
  },
 
  createRecharge: function () {
    var that=this;
    if (that.data.money>10000){
      wx.showToast({
        title: '金额不能超过10000',
        icon: 'none'
      })
      return;
    } else if (that.data.money==0){
      wx.showToast({
        title: '请输入正确的金额',
        icon : 'none'
      })
      return;
    }
    const data = {
      total: that.data.money
    };
    req.userRequest("请稍等", 'POST',url.pay['createRecharge'], data, function back(res){
      console.log(res)
      wx.navigateTo({
        url: '../recharge/recharge?orderNumber=' + res.data.orderNumber + '&money=' + res.data.money + '&createTime=' + res.data.createTime,
      })
    })  
    
  },
  
})